package com.example.service;

import com.example.entity.Course;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class CourseService {
    private List<Course> courses = new ArrayList<>();

    public CourseService() {
        courses.add(new Course(1, "Java"));
        courses.add(new Course(2, "Spring"));
    }

    public Course getCourseById(int id) {
        for (Course course : courses) {
            if (course.getId() == id) {
                return course;
            }
        }
        return null;
    }
}